package cn.com.codingce.student.servlet;

import cn.com.codingce.student.entity.Login;
import cn.com.codingce.student.service.ITeacherService;
import cn.com.codingce.student.service.impl.TeacherServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/UpdateTeacherServlet")
public class UpdateTeacherServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateTeacherServlet() {
        super();
        // TODO Auto-generated constructor stub
    }


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        /*
         * 获取修改人的学号
         */
        int no = Integer.parseInt(request.getParameter("id"));
        /*
         * 修改后的内容
         */
        int id = Integer.parseInt(request.getParameter("id"));
        String uname = request.getParameter("uname");
        String upwd = request.getParameter("upwd");
        /*
         * 将修改的内容封装到javaBean中
         */
        Login tea = new Login(id, uname, upwd);

        ITeacherService service = new TeacherServiceImpl();
        boolean result = service.updateTeacherById(no, tea);

        response.setContentType("text/html; charset=UTF-8");
        response.setCharacterEncoding("utf-8");
        if (result) {

            /*
             * response.getWriter().println("修改成功!");
             * 修改完成后，再次全部查询
             */
            response.sendRedirect("querybypage");
        } else {
            response.getWriter().println("修改失败!");
        }
    }


}
